package com.zhangpu.hystrix.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @Author: zhangpu
 * @License: (C) Copyright hualala.com Corporation Limited.
 * @Contact: zhangpu@hualala.com
 * @Date: 2021.07.20 11:02
 * @Version: 1.0
 * @Description:
 * @ProjectName: spring-cloud-eureka
 */

@Service
public class HystrixService {

    @Autowired
    private RestTemplate restTemplate;

    /**
     * 获取hiService中信息
     * @param name
     * @return
     */

    @HystrixCommand(fallbackMethod = "fastBackError")
    public String hiService(String name){
        return restTemplate.getForObject("http://SPRING-CLOUD-PRODUCER/hi/"+name,String.class);
    }

    /**
     * 快速失败
     * @param name
     * @return
     */
    public String fastBackError(String name){
        return "hi,"+name+"都失败了还在点。。。累不";
    }
}